const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    userInfo:'',
    page:1,
    pageSize:10,
    isEnd:false,
    lists:[],
    isloading:false,
    type:1,
  },
  onLoad() {
    
  },
  onShow(){
    if(!wx.getStorageSync('logintoken')){
      app.ToLogin()
      return
    }
    this.setData({
      page:1,
      pageSize:10,
      isEnd:false,
      lists:[],
    })
    this.contentlist()
    this.info()
  },
  info(){
    Controller.info().then(res=>{
      if(res.data.baseData){
        this.setData({
          userInfo:res.data.baseData
        })
      }
    })
  },
  tabs(e){
    this.setData({
      type:e.currentTarget.dataset.type,
      page:1,
      pageSize:10,
      isEnd:false,
      lists:[],
    })
    this.contentlist()
  },
  cash(){
    wx.navigateTo({
      url: "/pages/Me/cash"
    })
  },
  contentlist(){
    var data={
      page:this.data.page,
      pageSize:this.data.pageSize,
    }
    if(this.data.type==1){
      Controller.myUserRecord(data).then(res=>{
        if(res.data.baseData && res.data.baseData.list.length>0){
          this.setData({
            lists:this.data.lists.concat(res.data.baseData.list),
          })
        }
        if(res.data.baseData.lastPage){
          this.setData({
            isEnd:res.data.baseData.lastPage
          })
        }
        this.setData({
          isloading:false
        })
      })
    }else{
      Controller.withdrawallist(data).then(res=>{
        if(res.data.baseData && res.data.baseData.list.length>0){
          this.setData({
            lists:this.data.lists.concat(res.data.baseData.list),
          })
        }
        if(res.data.baseData.lastPage){
          this.setData({
            isEnd:res.data.baseData.lastPage
          })
        }
        this.setData({
          isloading:false
        })
      })
    }
  },
  onReachBottom(){
    if(this.data.isEnd){
      return
    }else{
      this.setData({
        page:this.data.page+1
      })
      this.contentlist()
    }
    
  },
  onPageScroll: function (e) { // 获取滚动条当前位置
    
  },
  onShareAppMessage: function (e) {
    
  },
  onShareTimeline: function(res){
    
  },

})